import React, { Component } from 'react';
import moment from 'moment'
import { connect } from 'react-redux'
import { Modal, Form, Table , Input,Select ,DatePicker ,Radio,Button,Row,Col,InputNumber} from 'antd';
import {date2str,replaceStr} from '../../services/common'
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
const Option =Select.Option;

class ServiceLifeModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
    };
  }
  cancelHandler=()=>{
    const { onCancel } = this.props;
    this.props.form.resetFields();
    onCancel();
  }
columns=[{title: '资产编号',dataIndex: 'assetNo',textAlign:'center',key: 'assetNo',width: 120,},
{title: '资产名称',dataIndex: 'assetName',key: 'assetName',width: 140,},
{title: '资产类型',dataIndex: 'typeName',key: 'typeName',width: 100,},
{title: '序列号',dataIndex: 'serialNo',key: 'serialNo',width: 140,},
{title: 'RFID号',dataIndex: 'rfidNo',key: 'rfidNo',width: 100,},
{
  title: '分配状态',dataIndex: 'isDistribute',key: 'isDistribute',width: 80,
  render: (value, row, index) => {return (value==1?'已分配':'未分配')},
},
{title: '状态',dataIndex: 'brandName',key: 'brandName',width: 100,},
{title: '型号',dataIndex: 'modelName',key: 'modelName',width: 100,},
{title: '机房',dataIndex: 'roomName',key: 'roomName',width: 120,},
{title: '使用年限',dataIndex: 'yearCount',key: 'yearCount',width: 80,},
{
  title: '创建时间',dataIndex: 'createTime',key: 'createTime',width: 120,
  render: (value, row, index) => {
    return (
      value==null?'':date2str(replaceStr(value), "yyyy-MM-dd hh:mm:ss")
    )
  },
}];

  render() {
    const { children, dispatch,item,pageSize,detailList,pageNum,total,roomId,brandId} = this.props;
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
    };
    const pagination = {
      current:pageNum,
      pageSize:pageSize,
      total: total,
      showSizeChanger: true,
      showTotal: (total => '共' + total + '条'),
      onShowSizeChange(current, size) {
        dispatch({
          type: 'serviceLifeLedger/showDataDetial',
          payload: {...{'pageNum':current, 'pageSize':size,id:brandId,roomId:roomId,} },
        });
      },
      onChange(current) {
        dispatch({
          type: 'serviceLifeLedger/showDataDetial',
          payload: {...{'pageNum':current, 'pageSize':pageSize,id:brandId,roomId:roomId,} },
        });
      },
    };
const width=1280;
const buttons=[
    <Button key="back" type="ghost" size="large" onClick={this.cancelHandler}>关闭</Button>,
  ];
    return (
      <span>
        <Modal
            title={this.props.title}
            visible={this.props.visible}
            onOk={this.okHandler}
            onCancel={this.cancelHandler}
            key={this.props.newKey}
            width={width}
            footer={buttons}
          >
          <Table
            columns={this.columns}
            dataSource={detailList}
            pagination={pagination}
            rowKey={record => record.id_}
          />
        </Modal>
      </span>
    );
  }

}

export default Form.create()(ServiceLifeModal)
